package com.green.business.controller;

import com.green.business.domain.Scrap;
import com.green.business.service.ScrapService;
import com.green.business.vo.ScrapVo;
import com.green.system.common.ActiveUser;
import com.green.system.common.ResultObj;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Green
 * @Date: 2021/10/22/16:31
 * @Description:
 */

@RequestMapping("scrap")
@RestController
public class ScrapController {

    @Autowired
    private ScrapService scrapService ;

    /**
     * 查询
     */
    @RequestMapping("loadAllScrap")
    public Object loadAllScrap(ScrapVo scrapVo){
        return this.scrapService.queryAllScrap(scrapVo);
    }

    /**
     * 添加报废信息
     */
    @RequestMapping("scrapGoods")
    public ResultObj scrapGoods(ScrapVo scrapVo){
        try{
            Scrap scrap = new Scrap();
            scrap.setGoodsid(scrapVo.getId());
            scrap.setGoodsname(scrapVo.getGoodsname());
            scrap.setProviderid(scrapVo.getProviderid());
            scrap.setProvidername(scrapVo.getProvidername());
            scrap.setNumber(scrapVo.getScrapNumber());
            scrap.setRemark(scrapVo.getRemark());
            scrap.setSize(scrapVo.getSize());
            ActiveUser activeUser = (ActiveUser) SecurityUtils.getSubject().getPrincipal();
            scrap.setOperateperson(activeUser.getUser().getName());
            scrap.setScraptime(new Date());

            this.scrapService.saveScrap(scrap);
            return ResultObj.SCRAP_SUCCESS;
        }catch (Exception e){
            e.printStackTrace();
            return ResultObj.SCRAP_ERROR;
        }

    }


}
